local quanji = fk.CreateSkill {

  name = "joy__quanji",

  tags = {  },

}



quanji:addEffect("active", {
  name = "joy__quanji",
  anim_type = "control",
  min_card_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and #player:getPile("joy__zhonghui_quan") < 51
  end,
  card_filter = function(self, player, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    player:addToPile("joy__zhonghui_quan", effect.cards, true, quanji.name)
  end,
})

quanji:addEffect(fk.Damaged, {
  name = "#joy__quanji_trigger",
  anim_type = "drawcard",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if self.cancel_cost or player.dead then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, quanji.name, data,"#joy__quanji") then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, quanji.name)
  end,
})

quanji:addEffect("maxcards", {
  name = "#joy__quanji_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(quanji.name) then
      return math.min(#player:getPile("joy__zhonghui_quan"),5)
    else
      return 0
    end
  end,
})

return quanji